/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define.dao.sale;

import cn.ekuma.data.dao.ModifiedLogDAO;
import cn.ekuma.epos.db.table.pos.I_TicketLine;
import cn.ekuma.util.JsonUtil;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;
import com.openbravo.bean.Tax;
import com.openbravo.bean.sales.Ticket;
import com.openbravo.bean.sales.TicketLine;
import com.openbravo.data.loader.ImageUtils;
import java.util.HashMap;

/**
 *
 * @author Administrator
 */
public class TicketLineDAO extends ModifiedLogDAO<TicketLine>{

    public TicketLineDAO(I_Session s) {
        super(s);
    }

    @Override
    public TableDefinition getTable() {
          return new TableDefinition(s,
                  "TICKETLINES",
                  new Field[]{
        		       new Field(I_TicketLine.ID,Datas.STRING,Formats.STRING,Ticket.class),
                       new Field(I_TicketLine.TICKET,Datas.STRING,Formats.STRING,Ticket.class),
                       new Field(I_TicketLine.LINE,Datas.INT,Formats.INT),
                       new Field(I_TicketLine.PRODUCT,Datas.STRING,Formats.STRING),
                       new Field(I_TicketLine.ATTRIBUTESETINSTANCE_ID,Datas.STRING,Formats.STRING),
                       new Field(I_TicketLine.UNITS,Datas.DOUBLE,Formats.DOUBLE),
                       
                       new Field(I_TicketLine.PRICE,Datas.DOUBLE,Formats.DOUBLE),
                       new Field(I_TicketLine.TAXID,Datas.STRING,Formats.STRING),
                       new Field(I_TicketLine.DEFAULTPRICE,Datas.DOUBLE,Formats.DOUBLE),
                       new Field(I_TicketLine.PRICERATE,Datas.DOUBLE,Formats.DOUBLE),
                       new Field(I_TicketLine.ISPREFSELL,Datas.BOOLEAN,Formats.BOOLEAN),
                       
                       new Field(I_TicketLine.ATTRIBUTES,Datas.STRING,Formats.STRING),
                       new Field(I_TicketLine.LASTMODIFIED,Datas.TIMESTAMP,Formats.TIMESTAMP),
                       new Field(I_TicketLine.CONSULTCOST,Datas.DOUBLE,Formats.DOUBLE),
                       new Field(I_TicketLine.LOTNO, Datas.STRING,Formats.STRING),	          
       				   new Field(I_TicketLine.VALIDITYDATE, Datas.TIMESTAMP, Formats.TIMESTAMP),
       				   new Field(I_TicketLine.SCORE,Datas.DOUBLE,Formats.DOUBLE),
       				   new Field(I_TicketLine.SALEMAN,Datas.STRING,Formats.STRING),
       				   new Field(I_TicketLine.DIFFPRICE,Datas.DOUBLE,Formats.DOUBLE),
       				   new Field(I_TicketLine.DIFFPRICECOST,Datas.DOUBLE,Formats.DOUBLE)
                      },
                  new int[]{0});
    }

    @Override
    public void writeInsertValues(DataWrite dp, TicketLine obj) throws BasicException {
    	dp.setString(1,obj.id);
        dp.setString(2, obj.m_sTicket);
        dp.setInt(3, new Integer(obj.m_iLine));
        dp.setString(4, obj.productid);
        dp.setString(5, obj.attsetinstid);
        dp.setDouble(6, obj.multiply);
        
        dp.setDouble(7, obj.price);
        dp.setString(8, obj.tax.getId());
        dp.setDouble(9, obj.defaultPrice);
        dp.setDouble(10, obj.priceRate);
        dp.setBoolean(11, obj.isPrefSell);
        
        dp.setString(12,JsonUtil.toString(obj.attributes));
        dp.setTimestamp(13,obj.getLastModified());
        dp.setDouble(14,obj.getConsultCost());
        dp.setString(15, obj.getLotNo());
        dp.setTimestamp(16,obj.getValidityDate());
        dp.setDouble(17,obj.getScore());
        
        dp.setString(18,obj.getSaleMan());
        dp.setDouble(19,obj.getAttrPrice());
        dp.setDouble(20, obj.getAttrPriceCost());
    }

    @Override
    public Class getSuportClass() {
        return TicketLine.class;
    }

    public TicketLine readValues(DataRead dr,TicketLine obj) throws BasicException {
        if(obj==null)
        	obj=new TicketLine();
        obj.setKey(dr.getString(1));
        obj.setM_sTicket(dr.getString(2));
        obj.setM_iLine( dr.getInt(3));
        obj.setProductid(dr.getString(4));
        obj.setAttsetinstid(dr.getString(5));
        obj.setMultiply(dr.getDouble(6));
        obj.setPrice(dr.getDouble(7));
        obj.setTax(new Tax(dr.getString(8)));
        obj.setDefaultPrice(dr.getDouble(9));
        obj.setPriceRate(dr.getDouble(10));
        obj.setPrefSell(dr.getBoolean(11));
        obj.setAttributes(JsonUtil.getHashMap(dr.getString(12)));
        obj.setLastModified(dr.getTimestamp(13));
        obj.setConsultCost(dr.getDouble(14));
        
        obj.setLotNo(dr.getString(15));
        obj.setValidityDate(dr.getTimestamp(16));
        obj.setScore(dr.getDouble(17));
        obj.setSaleMan(dr.getString(18));
        obj.setAttrPrice(dr.getDouble(19));
        obj.setAttrPriceCost(dr.getDouble(20));
        return obj;
    }
}
